const fs = require('fs');
const readline = require('readline');

async function processLog() {
    try {
        // 创建输入输出文件流
        const fileStream = fs.createReadStream('test/data.log');
        const outputStream = fs.createWriteStream('test/data_processed.log');

        const rl = readline.createInterface({
            input: fileStream,
            crlfDelay: Infinity
        });

        // 按行读取并处理
        for await (const line of rl) {
            // 跳过只包含大括号或 "Existing windows:" 的行
            if (line.trim() !== '{}' && 
                line.trim()!== ('Existing windows:')) {
                outputStream.write(line + '\n');
            }
        }

        console.log('日志处理完成！');
        outputStream.end();
    } catch (error) {
        console.error('处理日志时发生错误:', error);
    }
}

// 执行处理
processLog();